debugger
let label = $(泵站选择.id).combobox('getValue');
let text = $(泵站选择.id).combobox('getText');
let tagMap = {
    "total": ["YD_ANP_A_FIT_I_L", "YD_ANP_B_FIT_I_L", "YD_ANP_C_FIT_I_L", "YD_ANP_D_FIT_I_L", "YD_ANP_E_FIT_I_L", "YD_ANP_F_FIT_I_L", "YD_GRT_FIT_O_L", "YD4_GRT_EO_FIT_TotalValue", "YD4_GRT_WO_FIT_TotalValue", "YD4_FIT408_01_PauseValue", "123zll", "1234zll", "4zll"],
    "22": ["YD_SPR_LEVEL", "YD_SPR_ESP_FIT", "YD_SPR_ESP_FIT_L", "YD_SPR_RSP_FIT", "YD_SPR_RSP_FIT_L", "YD_SPR_ESP_FIT", "YD4_FIT408_01_PV_Out", "YD4_FIT408_01_PauseValue"],
    "23": ["YD_SPR_RSP_PO1_DI_RUN", "YD_SPR_RSP_PO2_DI_RUN", "YD_SPR_RSP_PO3_DI_RUN", "YD_SPR_RSP_PO4_DI_RUN", "YD_SPR_ESP_PO1_DI_RUN", "YD_SPR_ESP_PO2_DI_RUN", "YD_SST_VP_PO1_DI_RUN"],
    "24": ["YD_LCQCC_JK_H2S_Out", "YD_LCQCC_JK_NH3_Out", "YD_LCQCC_JK_JW_Out", "YD_LCQCC_CK_H2S_Out", "YD_LCQCC_CK_NH3_Out", "YD_LCQCC_CK_JW_Out", "YD_LCQCC_H2S_QC", "YD_LCQCC_NH3_QC", "YD_LCQCC_JW_QC", "YD_LCQCC_XDT_H2S_Out", "YD_LCQCC_XDT_NH3_Out", "YD_LCQCC_JYW_LIT", "YD_LCQCC_XHS_PH_Out", "YD_LCQCC_PSC_PH_Out"],
    "25": ["YD_LCQCC_JXB1_DI_RUN", "YD_LCQCC_JXB2_DI_RUN", "YD_LCQCC_SXB1_DI_RUN", "YD_LCQCC_SXB2_DI_RUN", "YD_LCQCC_JLB1_DI_RUN", "YD_LCQCC_JLB2_DI_RUN", "YD_LCQCC_PSB_DI_RUN", "YD_LCQCC_FJ_DI_RUN"],
    "10": ["YD_CAS_LIT_BN_PV", "YD_CAS_MLSS_BN_PV", "YD_ANP_BN_DO", "YD_CAS_LIT_BS_PV", "YD_CAS_MLSS_BS_PV", "YD_ANP_BS_DO", "YD_CAS_ORP_B", "YD_ANP_GRT_FIT_B_I", "YD_ANP_B_FIT_I_L"],
    "11": ["YD_ANP_BN_MIX_MO1_DI_RUN", "YD_ANP_BN_IRP_PO1_DI_RUN", "YD_ANP_BN_ESP_PO1_DI_RUN", "YD_ANP_BN_SKD_MO1_DI_RUN", "YD_ANP_BN_MIX_MO2_DI_RUN", "YD_ANP_BS_IRP_PO1_DI_RUN", "YD_ANP_BS_ESP_PO1_DI_RUN", "YD_ANP_BS_SKD_MO1_DI_RUN", "YD_ANP_BS_MIX_MO3_DI_RUN"],
    "12": ["YD_CAS_LIT_CN_PV", "YD_CAS_MLSS_CN_PV", "YD_ANP_CN_DO", "YD_CAS_LIT_CS_PV", "YD_CAS_MLSS_CS_PV", "YD_ANP_CS_DO", "YD_CAS_ORP_C", "YD_ANP_GRT_FIT_C_I", "YD_ANP_C_FIT_I_L"],
    "13": ["YD_ANP_CN_MIX_MO1_DI_RUN", "YD_ANP_CN_IRP_PO1_DI_RUN", "YD_ANP_CN_ESP_PO1_DI_RUN", "YD_ANP_CN_SKD_MO1_DI_RUN", "YD_ANP_CN_MIX_MO2_DI_RUN", "YD_ANP_CS_IRP_PO1_DI_RUN", "YD_ANP_CS_ESP_PO1_DI_RUN", "YD_ANP_CS_SKD_MO1_DI_RUN", "YD_ANP_CS_MIX_MO3_DI_RUN"],
    "14": ["YD_CAS_LIT_DN_PV", "YD_CAS_MLSS_DN_PV", "YD_ANP_DN_DO", "YD_CAS_LIT_DS_PV", "YD_CAS_MLSS_DS_PV", "YD_ANP_DS_DO", "YD_CAS_ORP_D", "YD_ANP_GRT_FIT_D_I", "YD_ANP_D_FIT_I_L"],
    "15": ["YD_ANP_DN_MIX_MO1_DI_RUN", "YD_ANP_DN_IRP_PO1_DI_RUN", "YD_ANP_DN_ESP_PO1_DI_RUN", "YD_ANP_DN_SKD_MO1_DI_RUN", "YD_ANP_DN_MIX_MO2_DI_RUN", "YD_ANP_DS_IRP_PO1_DI_RUN", "YD_ANP_DS_ESP_PO1_DI_RUN", "YD_ANP_DS_SKD_MO1_DI_RUN", "YD_ANP_DS_MIX_MO3_DI_RUN"],
    "16": ["YD_CAS_LIT_EN_PV", "YD_CAS_MLSS_EN_PV", "YD_ANP_EN_DO", "YD_CAS_LIT_ES_PV", "YD_CAS_MLSS_ES_PV", "YD_ANP_ES_DO", "YD_CAS_ORP_E", "YD_ANP_GRT_FIT_E_I", "YD_ANP_E_FIT_I_L"],
    "17": ["YD_ANP_EN_MIX_MO1_DI_RUN", "YD_ANP_EN_IRP_PO1_DI_RUN", "YD_ANP_EN_ESP_PO1_DI_RUN", "YD_ANP_EN_SKD_MO1_DI_RUN", "YD_ANP_EN_MIX_MO2_DI_RUN", "YD_ANP_ES_IRP_PO1_DI_RUN", "YD_ANP_ES_ESP_PO1_DI_RUN", "YD_ANP_ES_SKD_MO1_DI_RUN", "YD_ANP_ES_MIX_MO3_DI_RUN"],
    "18": ["YD_CAS_LIT_FN_PV", "YD_CAS_MLSS_FN_PV", "YD_ANP_FN_DO", "YD_CAS_LIT_FS_PV", "YD_CAS_MLSS_FS_PV", "YD_ANP_FS_DO", "YD_CAS_ORP_F", "YD_ANP_GRT_FIT_F_I", "YD_ANP_F_FIT_I_L"],
    "19": ["YD_ANP_FN_MIX_MO1_DI_RUN", "YD_ANP_FN_IRP_PO1_DI_RUN", "YD_ANP_FN_ESP_PO1_DI_RUN", "YD_ANP_FN_SKD_MO1_DI_RUN", "YD_ANP_FN_MIX_MO2_DI_RUN", "YD_ANP_FS_IRP_PO1_DI_RUN", "YD_ANP_FS_ESP_PO1_DI_RUN", "YD_ANP_FS_SKD_MO1_DI_RUN", "YD_ANP_FS_MIX_MO3_DI_RUN"],
    "1": ["YD_IPS_COD", "YD_IPS_NH3N", "YD_IPS_TP", "YD_IPS_TN", "YD_IPS_PH", "YD_GRT_FIT_I", "YD_GRT_FIT_O_L", "YD_DFP_COD", "YD_DFP_NH3", "YD_DFP_TP", "YD_DFP_OMR_TN", "YD_DFP_SS", "YD_DFP_PH", "YD4_FIT408_01_PV_Out", "YD4_FIT408_01_PauseValue"],
    "2": ["YD_IPS_LEVEL1", "YD_IPS_LEVEL2", "YD_IPS_SBP_PO1_CUR", "YD_IPS_SBP_PO2_CUR", "YD_IPS_SBP_PO3_CUR", "YD_IPS_SBP_PO4_CUR", "YD_IPS_SBP_PO5_CUR", "YD_IPS_SBP_PO6_CUR", "YD_FSR_LIT_N01_L", "YD_FSR_LIT_N02_L", "YD_GRT_FIT_I", "YD_GRT_FIT_O_L"],
    "3": ["YD_IPS_CSR_MO1_DI_RUN", "YD_IPS_CSR_M02_DI_RUN", "YD_IPS_SBP_PO1_DI_RUN", "YD_IPS_SBP_PO2_DI_RUN", "YD_IPS_SBP_PO3_DI_RUN", "YD_IPS_SBP_PO4_DI_RUN", "YD_IPS_SBP_PO5_DI_RUN", "YD_IPS_SBP_PO6_DI_RUN", "YD_GRT_FSR_MO1_DI_RUN", "YD_GRT_FSR_MO2_DI_RUN", "YD_GRT_SCV_MO1_DI_RUN", "YD_GRT1_RBL_BO1_DI_RUN", "YD_GRT1_RBL_BO2_DI_RUN", "YD_GRT1_MIX_MO1_DI_RUN", "YD_GRT2_MIX_MO1_DI_RUN", "YD_GRT1_GWS_MO1_DI_RUN"],
    "4": ["YD_ABH_RBL_PIT_BO1_P", "YD_ABH_RBL_PIT_BO2_P", "YD_ABH_RBL_PIT_BO3_P", "YD_ABH_RBL_PIT_BO4_P", "YD_ABH_RBL_PIT_BO5_P", "YD_ABH_RBL_PIT_BO6_P"],
    "5": ["YD_ABH_RBL_BO1_F_DI_RUN", "YD_ABH_RBL_BO1_PF_DI_RUN", "YD_ABH_RBL_BO2_F_DI_RUN", "YD_ABH_RBL_BO2_PF_DI_RUN", "YD_ABH_RBL_BO3_F_DI_RUN", "YD_ABH_RBL_BO3_PF_DI_RUN", "YD_ABH_RBL_BO4_F_DI_RUN", "YD_ABH_RBL_BO4_PF_DI_RUN", "YD_ABH_RBL_BO5_F_DI_RUN", "YD_ABH_RBL_BO5_PF_DI_RUN", "YD_ABH_RBL_BO6_F_DI_RUN", "YD_ABH_RBL_BO6_PF_DI_RUN"],
    "6": ["YD_GFJ1_B01_YCZ", "YD_GFJ1_B01_CKYLZ", "YD_GFJ1_B01_JKWDZ", "YD_GFJ1_B01_CKWDZ", "YD_GFJ1_B01_LL", "YD_GFJ1_B01_ZSZ", "YD_GFJ1_B01_SVFK", "YD_GFJ1_B02_YCZ", "YD_GFJ1_B02_CKYLZ", "YD_GFJ1_B02_JKWDZ", "YD_GFJ1_B02_CKWDZ", "YD_GFJ1_B02_LL", "YD_GFJ1_B02_ZSZ", "YD_GFJ1_B02_SVFK", "YD_GFJ1_B03_YCZ", "YD_GFJ1_B03_CKYLZ", "YD_GFJ1_B03_JKWDZ", "YD_GFJ1_B03_CKWDZ", "YD_GFJ1_B03_LL", "YD_GFJ1_B03_ZSZ", "YD_GFJ1_B03_SVFK"],
    "7": ["YD_GFJ1_B01_DI_RUN", "YD_GFJ1_B02_DI_RUN", "YD_GFJ1_B03_DI_RUN"],
    "8": ["YD_CAS_LIT_AN_PV", "YD_CAS_MLSS_AN_PV", "YD_ANP_AN_DO", "YD_CAS_LIT_AS_PV", "YD_CAS_MLSS_AS_PV", "YD_ANP_AS_DO", "YD_CAS_ORP_A", "YD_ANP_GRT_FIT_A_I", "YD_ANP_A_FIT_I_L"],
    "9": ["YD_ANP_AN_MIX_MO1_DI_RUN", "YD_ANP_AN_IRP_PO1_DI_RUN", "YD_ANP_AN_ESP_PO1_DI_RUN", "YD_ANP_AN_SKD_MO1_DI_RUN", "YD_ANP_AN_MIX_MO2_DI_RUN", "YD_ANP_AS_IRP_PO1_DI_RUN", "YD_ANP_AS_ESP_PO1_DI_RUN", "YD_ANP_AS_SKD_MO1_DI_RUN", "YD_ANP_AS_MIX_MO3_DI_RUN"],
    "20": ["YD_OXD_DO1", "YD_OXD_DO2", "YD_OXD_DO3", "YD_OXD_ORP", "YD_OXD_ORP_D_Value", "YD_OXD_ORP_TEMP_D_Value", "YD_OXD_N03N", "YD_OXD_MLSS", "YD_OXD_PH", "YD_SPR_RSP_FIT", "YD4_AAO_FIT_306_03_PV_Out", "YD4_AAO_FIT_306_03_TotalValue", "YD4_AAO_FIT_306_02_PV_Out", "YD4_AAO_FIT_306_02_TotalValue", "YD4_AAO_FIT_306_01_PV_Out", "YD4_AAO_FIT_306_01_TotalValue"],
    "21": ["YD_OXD_SPS_MO1_DI_RUN", "YD_OXD_SPS_MO2_DI_RUN", "YD_OXD_SPS_MO3_DI_RUN", "YD_OXD_SPS_MO4_DI_RUN", "YD_OXD_SPS_MO5_DI_RUN", "YD_OXD_SPS_MO6_DI_RUN", "YD_OXD_SPS_MO7_DI_RUN", "YD_OXD_SPS_MO8_DI_RUN", "YD_OXD_SPS_MO9_DI_RUN", "YD_OXD_CFP_PO1_DI_RUN", "YD_OXD_CFP_PO2_DI_RUN", "YD_OXD_CFP_PO3_DI_RUN"]
}

let hasTotal = false;
for (let i = 0; i < tagMap[label].length; i++) {
    let tagName = tagMap[label][i];
    if (tagName.indexOf("_FIT_I_L") !== -1 || tagName.indexOf("_FIT_O_L") !== -1 || tagName.indexOf("_PauseValue") !== -1 || tagName.indexOf("_FIT_TotalValue") !== -1) {
        hasTotal = true;
        break;
    }
}

$(Datagrid1.id).datagrid({
    data: [],
    fitColumns: false,
    pagination: true,
    nowrap: false,
    pageList: [50, 80, 100, 120, 150], //设置每页记录条数的列表
}); //清空
//自定义返回月的天数
function getDaysInMonth(year, month) {
    month = parseInt(month, 10);
    var temp = new Date(year, month, '0');
    return temp.getDate();
}
//自定义返回增加的n天的日期
function getaddriqi(year, month, day, n) {
    var temp = new Date(year, month - 1, day);
    temp = new Date(temp.getTime() + 24 * 60 * 60 * 1000 * n);
    temp = temp.format('yyyy-MM-dd');
    return temp;
}
let SLRQ = new Date(DateTimeBox1.Value)
let year1 = SLRQ.getFullYear(); //返回所选年份
let month1 = SLRQ.getMonth() + 1; //返回所选月份
let day1 = SLRQ.getDate(); //返回所选天
let getmonthday = getDaysInMonth(year1, month1); //自定义返回月的天数
// 获取到开始时间后面的日期时间框的数据
let startTime;
// 获取到结束时间后面的日期时间框的数据
let endTime;
let endTimeacc;
var endtnum;
var type1;
var maxendtime, maxendtnum;
let currriqi = $System.$Date;
currriqi = currriqi.replace(/\//g, "-");
// 查询间隔时间
//let timebucket = "60m";
let timebucket = 间隔.GetCurrentText() + "m";
let reporttype;
if (报表类型.GetCurrentText() === '日报表') {
    type1 = 0;
    reporttype = "日报表";
    startTime = DateTimeBox1.Value + ' 00:00:05';
    endTime = DateTimeBox1.Value + ' 23:59:59';
    endTimeacc = getaddriqi(year1, month1, day1, 1) + ' 00:00:05';
    if (currriqi === DateTimeBox1.Value) {
        var currTime = new Date();
        endTime = currTime.format('yyyy-MM-dd hh:mm:ss');
        endTimeacc = endTime;
    }
    endtnum = new Date(DateTimeBox1.Value);
    maxendtime = getaddriqi($System.$Year, $System.$Month, $System.$Day, 0);
    maxendtnum = new Date(maxendtime);
} else if (报表类型.GetCurrentText() === '月报表') {
    type1 = 1;
    reporttype = "月报表";
    timebucket = "1d";
    startTime = getaddriqi(year1, month1, 1, 0) + ' 00:00:00';
    endTime = getaddriqi(year1, month1, getmonthday, 0) + ' 23:59:59';
    endTimeacc = getaddriqi(year1, month1, getmonthday, 1) + ' 00:00:05';
    if (year1 == $System.$Year && month1 == $System.$Month) {
        var currTime1 = new Date();
        endTime = currTime1.format('yyyy-MM-dd hh:mm:ss');
        endTimeacc = endTime;
    }
    endtnum = new Date(getaddriqi(year1, month1, getmonthday, 1));
    maxendtime = getaddriqi($System.$Year, $System.$Month, getDaysInMonth($System.$Year, $System.$Month), 1);
    maxendtnum = new Date(maxendtime);
} else if (报表类型.GetCurrentText() === '年报表') {
    type1 = -1;
    reporttype = "年报表";
    timebucket = "1n";
    startTime = getaddriqi(year1, 1, 1, 0) + ' 00:00:00';
    endTime = getaddriqi(year1, 12, 31, 0) + ' 23:59:59';
    endTimeacc = getaddriqi(year1 + 1, 1, 1, 0) + ' 00:00:05';
    if (year1 == $System.$Year && month1 <= $System.$Month) {
        var currTime1 = new Date();
        endTime = currTime1.format('yyyy-MM-dd hh:mm:ss');
        endTimeacc = endTime;
    }
    endtnum = new Date(getaddriqi(year1, 12, 31, 1));
    maxendtime = getaddriqi($System.$Year, 12, 31, 1);
    maxendtnum = new Date(maxendtime);
}
let datatype;
if (数据类型.GetCurrentText() === '瞬时') {
    datatype = 'data_first';
} else if (数据类型.GetCurrentText() === '平均') {
    datatype = 'data_average';
} else if (数据类型.GetCurrentText() === '最大') {
    datatype = 'data_max';
} else if (数据类型.GetCurrentText() === '最小') {
    datatype = 'data_min';
}
if (报表类型.GetCurrentText() === '月报表' || 报表类型.GetCurrentText() === '年报表') {数据类型.SetCurrentText
    datatype = 'data_average';
}
startTime = startTime.replace(/\//g, "-");
endTime = endTime.replace(/\//g, "-");
//判断
if (endtnum > maxendtnum) {
    alert('时间选择错误！');
} else if (datatype === 'data_first') {
    let options;
    if (hasTotal) {
        options = {
            "type": type1,
            "startTime": startTime,
            "endTime": endTimeacc,
            "timebucket": timebucket,
            "tags": tagMap[label],
            "columns": []
        };
    } else {
        options = {
            "type": type1,
            "startTime": startTime,
            "endTime": endTime,
            "timebucket": timebucket,
            "tags": tagMap[label],
            "columns": []
        };
    }
    GetHistorytagForReport(options, function(res) {
        debugger
        datadealfun(res.Body.records)
    })
} else {
    let options;
    if (hasTotal) {
        options = {
            "startTime": startTime,
            "endTime": endTimeacc,
            "timebucket": timebucket,
            "tags": tagMap[label],
            "columns": ["max", "min", "last", "avg"],
            "isDesc": false
        };
    } else {
        ooptions = {
            "startTime": startTime,
            "endTime": endTime,
            "timebucket": timebucket,
            "tags": tagMap[label],
            "columns": ["max", "min", "last", "avg"],
            "isDesc": false
        };
    }
    GetHistorytagForCurve(options, function(res) {
        debugger
        datadealfun(res.Body.records)
    });
}

function datadealfun(res) {
    let dataY = [];
    let arrLen = 0;
    for (const key in res) {
        if (res[key].length > arrLen) {
            arrLen = res[key].length;
        }
    }
    if (hasTotal || endTime === endTimeacc) {
        arrLen = arrLen - 1;
    }
    for (let i = 0; i < arrLen; i++) {
        let dataT = {};
        //max:datamax min:datamin avg:dataaverage
        dataT.time = null;
        let zll123 = null;
        let zll4 = null;
        let zll1234 = null;
        for (let j = 0; j < tagMap[label].length; j++) {
            if (dataT.time === null) {
                if (res[tagMap[label][j]] && res[tagMap[label][j]][i] && res[tagMap[label][j]][i].period) {
                    dataT.time = res[tagMap[label][j]][i].period;
                    var sj = new Date(dataT.time);
                    dataT.time = sj.format('hh:mm:00');
                    if (报表类型.GetCurrentText() === '月报表') {
                        dataT.time = sj.format('yyyy-MM-dd');
                    }
                    if (报表类型.GetCurrentText() === '年报表') {
                        dataT.time = sj.format('yyyy-MM');
                    }
                }
            }
            if (res[tagMap[label][j]] && res[tagMap[label][j]][i]) {
                if (tagMap[label][j].indexOf("_FIT_O_L") !== -1 || tagMap[label][j].indexOf("_FIT_I_L") !== -1 || tagMap[label][j].indexOf("_PauseValue") !== -1 || tagMap[label][j].indexOf("_FIT_TotalValue") !== -1) {
                    let thisData = res[tagMap[label][j]][i][datatype] ? parseFloat(res[tagMap[label][j]][i][datatype].toFixed(2)) : 0;
                    let nextData = res[tagMap[label][j]][i + 1][datatype] ? parseFloat(res[tagMap[label][j]][i + 1][datatype].toFixed(2)) : 0;
                    dataT[tagMap[label][j]] = parseFloat((nextData - thisData).toFixed(2));
                } else {
                    dataT[tagMap[label][j]] = res[tagMap[label][j]][i][datatype] ? parseFloat(res[tagMap[label][j]][i][datatype].toFixed(2)) : 0
                }
            }
            if (label === 'total'){
                if (["YD_ANP_A_FIT_I_L","YD_ANP_B_FIT_I_L","YD_ANP_C_FIT_I_L","YD_ANP_D_FIT_I_L","YD_ANP_E_FIT_I_L","YD_ANP_F_FIT_I_L","YD_GRT_FIT_O_L"].indexOf(tagMap[label][j]) !== -1){
                    let addData = dataT[tagMap[label][j]];
                    if (addData == null){
                        addData = 0;
                    }
                    zll123 += addData;
                    zll1234 += addData;
                }else if (["YD4_GRT_EO_FIT_TotalValue","YD4_GRT_WO_FIT_TotalValue"].indexOf(tagMap[label][j]) !== -1){
                    let addData = dataT[tagMap[label][j]];
                    if (addData == null){
                        addData = 0;
                    }
                    zll4 += addData;
                    zll1234 += addData;
                }
            }
        }
        if (label === 'total'){
            dataT["123zll"] = zll123;
            dataT["4zll"] = zll4;
            dataT["1234zll"] = zll1234;
        }
        dataY.push(dataT);
    }
    console.log(dataY);
    //计算数据
    //最大值判断函数定义
    Array.prototype.max = function() {
        var max = this[0];
        this.forEach(function(ele, index, arr) {
            if (ele > max) {
                max = ele;
            }
        })
        return max;
    }
    //最小值判断函数定义
    Array.prototype.min = function() {
        var min = this[0];
        this.forEach(function(ele, index, arr) {
            if (ele < min) {
                min = ele;
            }
        })
        return min;
    }
    //最小值
    let minData = {}
    minData.time = '最小值';
    for (let i = 0; i < tagMap[label].length; i++) {
        let dataArr = [];
        for (var iq = 0; iq < dataY.length; iq++) {
            if (dataY[iq][tagMap[label][i]] !== null && dataY[iq][tagMap[label][i]] !== undefined) {
                dataArr.push(dataY[iq][tagMap[label][i]])
            }
        }
        if (dataArr.length > 0) {
            let min = dataArr.min();
            minData[tagMap[label][i]] = min;
        }
    }
    let maxData = {}
    maxData.time = '最大值';
    for (let i = 0; i < tagMap[label].length; i++) {
        let dataArr = [];
        for (var iq = 0; iq < dataY.length; iq++) {
            if (dataY[iq][tagMap[label][i]] !== null && dataY[iq][tagMap[label][i]] !== undefined) {
                dataArr.push(dataY[iq][tagMap[label][i]])
            }
        }
        if (dataArr.length > 0) {
            let max = dataArr.max();
            maxData[tagMap[label][i]] = max;
        }
    }
    let avgData = {}
    avgData.time = '平均值';
    var sumFunc = function(x, y) {
        return x + y;
    }; //求和
    for (let i = 0; i < tagMap[label].length; i++) {
        let dataArr = [];
        for (var iq = 0; iq < dataY.length; iq++) {
            if (dataY[iq][tagMap[label][i]] !== null && dataY[iq][tagMap[label][i]] !== undefined) {
                dataArr.push(dataY[iq][tagMap[label][i]])
            }
        }
        if (dataArr.length > 0) {
            let sum = dataArr.reduce(sumFunc);
            let avg = parseFloat((sum / dataArr.length).toFixed(2));
            avgData[tagMap[label][i]] = avg;
        }
    }
    let cumulativeData = {}
    cumulativeData.time = '累计值';
    var sumFunc = function(x, y) {
        return x + y;
    }; //求和
    for (let i = 0; i < tagMap[label].length; i++) {
        if (tagMap[label][i].indexOf("_FIT_O_L") !== -1
            || tagMap[label][i].indexOf("_FIT_I_L") !== -1
            || tagMap[label][i].indexOf("_PauseValue") !== -1
            || tagMap[label][i].indexOf("_FIT_TotalValue") !== -1
            || tagMap[label][i].indexOf("123zll") !== -1
            || tagMap[label][i].indexOf("1234zll") !== -1
            || tagMap[label][i].indexOf("4zll") !== -1) {
            let dataArr = [];
            for (var iq = 0; iq < dataY.length; iq++) {
                if (dataY[iq][tagMap[label][i]] !== null && dataY[iq][tagMap[label][i]] !== undefined) {
                    dataArr.push(dataY[iq][tagMap[label][i]])
                }
            }
            if (dataArr.length > 0) {
                let sum = dataArr.reduce(sumFunc);
                cumulativeData[tagMap[label][i]] = parseFloat(sum.toFixed(2));
            }
        }else{
            cumulativeData[tagMap[label][i]] = null;
        }

    }
    dataY.push(minData);
    dataY.push(maxData);
    dataY.push(avgData);
    if(hasTotal){
        dataY.push(cumulativeData);
    }

    console.log(dataY);
    //数据网格分页显示
    var tmpData = dataY.slice(0, 50);
    $(Datagrid1.id).datagrid({
        data: tmpData,
        fitColumns: false,
        pagination: true,
        nowrap: false,
        pageList: [50, 80, 100, 120, 150], //设置每页记录条数的列表
    });
    var pager = $(Datagrid1.id).datagrid("getPager"); //数据网格分页对象
    pager.pagination({
        total: dataY.length,
        beforePageText: '第', //页数文本框前显示的汉字
        afterPageText: '页     共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录    共 {total} 条记录',
        onSelectPage: function(pageNo, pageSize) {
            var start = (pageNo - 1) * pageSize;
            var end = start + pageSize;
            tmpData = dataY.slice(start, end);
            $(Datagrid1.id).datagrid("loadData", tmpData);
            pager.pagination('refresh', {
                total: dataY.length,
                pageNumber: pageNo,
            });
        }
    });
}